package com.liaoban.app.ui.base;

import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;
import android.view.View;

import com.liaoban.app.R;
import com.liaoban.app.adapter.MFragmentPagerAdapter;

import butterknife.BindView;

/**
 * Created by ChenYuYun on 2018/3/30.
 * tabHost Fragment 基类
 */
public abstract class BaseTabHostFragment extends BaseFragment {
    @BindView(R.id.main_tab)
    public TabLayout mainTab;
    @BindView(R.id.main_viewpager)
    public ViewPager mainViewpager;

    @Override
    protected int getLayoutResID() {
        return R.layout.fragment_tabhost;
    }

    @Override
    protected void initView(View contentView) {
        MFragmentPagerAdapter mAdapter = new MFragmentPagerAdapter(getChildFragmentManager(), getFragmentList(), getTitleList(), getBundles());
        mainViewpager.setAdapter(mAdapter);
        mainTab.setupWithViewPager(mainViewpager);
        mainTab.setTabMode(TabLayout.MODE_FIXED);
    }

    /**
     * 获取tabHost标题列表
     *
     * @return
     */
    protected abstract String[] getTitleList();

    /**
     * 获取tabHost下的页面集合
     *
     * @return
     */
    protected abstract Class[] getFragmentList();

    protected abstract Bundle[] getBundles();


    @Override
    public void onDestroyView() {
        super.onDestroyView();
        mainTab = null;
    }

}
